package com.edu.controller;/**
 * @Author:hcb
 * @Date:2025/9/19-09-19-12:28
 */

import com.edu.service.GoodsService;
import com.edu.service.impl.GoodsServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 *@Author:hcb
 *@Date:2025/9/19-09-19-12:28
 */
@WebServlet("/getGoods.do")
public class GetGoodsServlet extends HttpServlet {
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        GoodsService gs = new GoodsServiceImpl();
        int pageNum ;
        int pageSize;
        try {
            pageNum = Integer.parseInt(req.getParameter("pageNum"));
        } catch (NumberFormatException e) {
            pageNum = 1;
        }
        try {
            pageSize = Integer.parseInt(req.getParameter("pageSize"));
        } catch (NumberFormatException e) {
            pageSize = 2;
        }

        if(req.getParameter("pageNum")!=null) {
            pageNum = Integer.parseInt(req.getParameter("pageNum"));
        }

        if(req.getParameter("pageSize")!=null) {
            pageSize = Integer.parseInt(req.getParameter("pageSize"));
        }
        req.setAttribute("page", gs.getAllGoods(pageNum, pageSize));
        req.getRequestDispatcher("goods.jsp").forward(req, resp);

    }


}
